<template>
  <div class="app-container">
    <!-- <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="88px">
      <el-form-item>
        <el-button type="primary" icon="el-icon-upload2" size="mini" @click="uploading = true">更新</el-button>
      </el-form-item>
    </el-form> -->
    <el-table v-loading="loading" :data="streetList" @selection-change="handleSelectionChange">
      <el-table-column label="编号"  align="left" prop="id"/>
      <el-table-column label="名称"  align="left" prop="title"/>
      <el-table-column label="居委(个)"  align="left" prop="sonNumber"/>
      <el-table-column label="操作" align="left" class-name="small-padding fixed-width">
        <template slot-scope="scope">
            <el-button icon="el-icon-search" circle @click="handleClick(scope.row.list)"></el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!--- 查看街道 -->
    <el-dialog :title="title" :visible.sync="particulars" width="600px" append-to-body :before-close="particulars">
        <el-table  :data="streetListSon" @selection-change="handleSelectionChange" max-height="500">
          <el-table-column label="居委"  align="left" prop="title"/>
          <el-table-column label="路名"  align="left" prop="somNumberB"/>
          <el-table-column label="范围"  align="left" prop="fw"/>
        </el-table>
    </el-dialog>
  </div>
</template>

<script>
import { listStreet, getStreet, delStreet, addStreet, updateStreet, exportStreet } from "@/api/assess/street";

export default {
  name: "Street",
  
  data() {
    return {
      dialogLimit:1,
      fileList:[],
      uploading:false,
      particulars:false,
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 街道管理表格数据
      streetList: [],
      // 弹出层标题
      title: "",
      streetListSon:[],
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      formInline: null,
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    beforeAvatarUpload(file) {
        let Xls = file.name.split('.');
        if(Xls[1] === 'xls'||Xls[1] === 'xlsx'){
          return file
        }else {
          this.$message.error('上传文件只能是 xls/xlsx 格式!')
          return false
        }

      },
     handleRemove(file, fileList) {
        console.log(file, fileList);
      },
      handlePreview(file) {
        console.log(file);
      },
     submitUpload() {
        this.$refs.upload.submit();
      },
    /** 查询街道管理列表 */
    getList() {
      this.loading = true;
      listStreet(this.queryParams).then(response => {
        this.streetList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        name: null,
        type: null,
        scope: null,
        pid: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        somNumber: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加街道管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getStreet(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改街道管理";
      });
    },
    handleClose(done) {
       this.uploading = false;
       this.handleClose = false;
       this.particulars = false;
    },
    handleClick(value){
      this.streetListSon = value;
      this.particulars = true;
      
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateStreet(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addStreet(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除街道管理编号为"' + ids + '"的数据项？').then(function() {
        return delStreet(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$modal.confirm('是否确认导出所有街道管理数据项？').then(() => {
        this.exportLoading = true;
        return exportStreet(queryParams);
      }).then(response => {
        this.$download.name(response.msg);
        this.exportLoading = false;
      }).catch(() => {});
    }
  }
};
</script>
